package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/shoppingCart")
@Api(tags = "用户购物车功能")
@Slf4j
public class ShoppingCartController {
    @Autowired
    private ShoppingCartService shoppingCartService;


    /**
     * @description 添加商品进购物车的功能
     * @author Administrator
     * @param[1] shoppingCartDTO
     * @throws
     * @return Result
     * @time 2023/12/2 16:00
     */
    @ApiOperation("添加入购物车的功能")
    @PostMapping("/add")
    public Result insertShoppingCart(@RequestBody ShoppingCartDTO shoppingCartDTO) {

        log.info("正在执行添加入购物车的功能........添加的信息为:{}", shoppingCartDTO);

        shoppingCartService.insertShoppingCart(shoppingCartDTO);

        return Result.success();

    }

    /**
     * @description 查询购物车的功能
     * @author Administrator

     * @throws
     * @return Result<List<ShoppingCart>>
     * @time 2023/12/2 16:00
     */

    @ApiOperation("查询购物车的功能")
    @GetMapping("/list")
    public Result<List<ShoppingCart>> selectShoppingCart() {

        log.info("正在执行查询购物车的功能........");

        List<ShoppingCart> shoppingCarts = shoppingCartService.selectShoppingCart();

        return Result.success(shoppingCarts);
    }

    /**
     * @description 删除购物车中一个商品的功能
     * @author Administrator
     * @param[1] shoppingCartDTO
     * @throws
     * @return Result
     * @time 2023/12/2 16:00
     */

    @ApiOperation("删除购物车中一个商品的功能")
    @PostMapping("/sub")
    public Result deleteShoppingCart(@RequestBody ShoppingCartDTO shoppingCartDTO) {

        log.info("正在执行删除购物车中一个商品的功能......删除的信息为:{}", shoppingCartDTO);

        shoppingCartService.deleteShoppingCart(shoppingCartDTO);

        return Result.success();

    }
    /**
     * @description 清空购物车的功能
     * @author Administrator

     * @throws
     * @return Result
     * @time 2023/12/2 16:00
     */

    @ApiOperation("清空购物车的功能")
    @DeleteMapping("/clean")
    public Result deleteAll() {

        log.info("正在执行清空购物车的功能.......");

        shoppingCartService.deleteAllShoppingCart();

        return Result.success();


    }
}
